// This file is a part of ChaosDB.
// Copyright (C) 2012 ChaoJianPeng
// email:chaojianpeng@gmail.com
//
// ChaosDB is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// ChaosDB is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

/*
 * byte_array.h
 * 二进制流处理
 * 写入流 不负责close的操作
 *  Created on: 2012-4-10
 *      Author: chao
 */

#ifndef BYTE_ARRAY_H_
#define BYTE_ARRAY_H_

#define BYTE_ARRAY_EOF -1
#define BYTE_ARRAY_OK 0
const int WRITE_BUFF_INIT_SIZE = 65536;

#define SIZE_INT sizeof(int)

typedef struct ByteArray{
	void* data;
	int pos;
	int size;
}ByteArray;

void creatReadByteArray(ByteArray* barr, void* data, int size);
int readInt(int* dest, ByteArray* barr);
int readString(char* dest, ByteArray* barr, int size);
int readBuff(void* dest, ByteArray* barr, int size);

void creatWriteByteArray(ByteArray* barr);
int writeInt(const int* src, ByteArray* barr);
int writeString(char* src, ByteArray* barr, int size);
int writeBuff(void* src, ByteArray* barr, int size);
void closeWriteByteArray(ByteArray* barr);


#endif /* BYTE_ARRAY_H_ */
